package cn.tedu.order.service;

import cn.HK.po.Order;
import cn.tedu.order.mapper.StateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class StateService {
    @Autowired(required = false)
    private StateMapper stateMapper;

    public void queryState(Order order) {
        Date start = order.getoStart();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");//设置日期格式
        String a = df.format(new Date());// new Date()为获取当前系统时间
        try {
            Date datestart= df.parse(a);
            if (start.getTime() < datestart.getTime()){
                stateMapper.updateState(order);
            }else {
                return;
            }
            //监听结束时间
            Date end = order.getoEnd();
            if (end.getTime() < datestart.getTime()){
                stateMapper.updateEnd(order);
            }else {
                return;
            }

        }catch (Exception e){
            e.printStackTrace();
        }




        }
}
